package com.first.orange.service.impl;

import com.first.orange.beans.Cart;
import com.first.orange.beans.UserCollection;
import com.first.orange.mapper.CartMapper;
import com.first.orange.service.CartService;
import com.first.orange.util.JDResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * Created on 2021/7/6.
 * <p>
 * Author: 190120
 * <p>
 * Description:
 */
@Service("cartService")
public class CartServiceImpl implements CartService {

    @Autowired(required = false)
    private CartMapper cartMapper;

    @Override
    public List<Cart> queryCartList(Integer userId) {
        return cartMapper.selectCartList(userId);
    }

    @Override
    public boolean delCart(Integer carId, Integer userId) {
        return cartMapper.deleteCart(carId, userId) > 0;
    }

    @Override
    public int addCarts(Cart cart) {
        return cartMapper.insertCarts(cart);
    }


    @Override
    public boolean addColle(Integer productId, Integer userId) {
        return cartMapper.insertColl(productId, userId) > 0;
    }

    @Override
    public boolean updataCarts(String carId, String checked, String quantity, String amount) {
        return cartMapper.upCarts(carId, checked, quantity, amount) > 0;
    }

    @Override
    public boolean updataAllCarts(String checked, String che) {
        return cartMapper.upAllCarts(checked, che) >= 0;
    }

    @Override
    public UserCollection selproductId(Integer productId, Integer userId) {
        return cartMapper.selectcoll(productId, userId);
    }

    @Override
    public Cart selectCartByUTPP(Cart cart) {
        System.out.println(cartMapper.selectCartByUTPP(cart));
        return cartMapper.selectCartByUTPP(cart);
    }

    @Override
    public int updataCart(Cart cart) {
        return cartMapper.upCart(cart);
    }


}
